package com.example.demo.controller;

import com.example.demo.entity.Bounter;
import com.example.demo.mapper.BounterMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Optional;

@RestController
@RequestMapping("test")
public class TestController {
    @Autowired
    private BounterMapper dao;

    @GetMapping("add")
    public String add() {
        Bounter bounter = new Bounter();
        bounter.setName("test1");
        bounter.setValue("value2");
        bounter.setTimestamp(new Date());
        dao.insertSelective(bounter);
        return "添加成功";
    }
    @GetMapping("find")
    public String find(Long id) {
        Bounter bounter = dao.selectByPrimaryKey(id);
        return bounter ==null?"找不到":bounter.getName();
    }
}
